<template >
  <div class="add_con_form tl" v-loading="loading">
    <el-dialog
      :title="mytitle"
      :modal-append-to-body="false"
      :visible.sync="visible"
      :show="show"
      :before-close="closeDialog"
      @close="$emit('update:show',false)"
      class="tl size_13"
      width="800px"
    >
      <el-form :model="data" :rules="dataYZ" ref="data" label-width="120px">
        <el-form-item label="标题" prop="m_title">
          <el-col :span="12">
            <el-input placeholder v-model="data.title" clearable></el-input>
          </el-col>
        </el-form-item>

        <el-form-item label="天数" prop="m_day">
          <el-col :span="12">
            <el-input placeholder v-model="data.day" clearable></el-input>
          </el-col>
        </el-form-item>

        <el-form-item label="投资金额" prop="m_price">
          <el-col :span="12">
            <el-input v-Int placeholder v-model="data.price" clearable></el-input>
          </el-col>
        </el-form-item>

        <el-form-item label="收益千分比" prop="income">
          <el-col :span="12">
            <el-input v-Int placeholder v-model="data.income" clearable>
              <template slot="append">‰</template>
            </el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="水滴收益千分比" prop="waterdrop">
          <el-col :span="12">
            <el-input v-Int placeholder v-model="data.waterdrop" clearable>
              <template slot="append">‰</template>
            </el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="冻结usdt千分比" prop="freeze">
          <el-col :span="12">
            <el-input v-Int placeholder v-model="data.freeze" clearable>
              <template slot="append">‰</template>
            </el-input>
          </el-col>
        </el-form-item>
        
        <el-form-item>
          <el-button
            :loading="$store.state.isLoading"
            size="medium"
            type="primary"
            @click="subForm()"
          >确定</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>




<style lang="less" scoped>
</style>

<script>
export default {
  data() {
    return {
      mytitle: "",
      fileList2: [],
      fileList: [],
      updateUrl: "",
      showImg: true,
      value: "",
      data: {
        title: "",
        price: "",
        day: "",
        income: ""
      },
      loading: false,
      dataYZ: {
        title: [{ required: true, message: "请输入名称", trigger: "blur" }]
      },
      visible: this.show
    };
  },
  props: {
    show: Boolean,
    editId: String,
    clickNum: Number
  },
  methods: {
    getDetails(id) {
      var data = {};
      data["id"] = id;
      this.$api.getDapp.getDappProductDetail(data).then(res => {
        this.data = res.data.result;
        this.data.id = id;
      });
    },

    closeDialog() {
      this.visible = false;
    },

    subForm() {
      if (this.editId == undefined) {
        this.AddNews();
      } else {
        this.UpdateNews();
      }
    },

    AddNews() {
      this.$refs["data"].validate(valid => {
        if (valid) {
          var params = {};
          params = this.data;
          this.$api.getDapp.SaveAddDappProduct(params).then(res => {
            if (res.data.status == 1 && res.data.code == 200) {
              this.$fnc.alertSuccess({ text: "添加成功" });
              this.$emit("parent", "这里刷新父页面");
              this.visible = false;
            } else {
              if (res.data.result == "stage已存在") {
                res.data.result = "期数已存在";
              }
              this.$fnc.alertError(res.data.code_desc, res.data.result);
            }
          });
        }
      });
    },

    UpdateNews() {
      this.data.id = this.editId;
      this.$api.getDapp.SaveEditDappProduct(this.data).then(res => {
        if (res.data.code == 200 && res.data.result != null) {
          this.$emit("parent", "这里刷新父页面");
          this.$fnc.alertSuccess({ text: "编辑成功" }); //成功弹出框
          this.visible = false;
        } else {
          this.$fnc.alertError(res.data.result); //失败弹出框
        }
      });
    }
  },
  watch: {
    show() {
      this.visible = this.show;
    },
    clickNum() {
      if (this.editId !== undefined) {
        this.mytitle = "编辑产品";
        this.getDetails(this.editId);
      } else {
        this.data = {};
        this.mytitle = "添加产品";
      }
    }
  },
  mounted() {},
  created() {},
  updated() {}
};
</script>
